<template>
  <div class="order-item" @click="onView">
    <div class="title">
      <span class="van-ellipsis w-240">{{`${orderData.orderCityName || ''}熊猫不走蛋糕`}}</span>
      <span class="status" :style="getStatusStyle(orderData)">{{getStatusText(orderData)}}</span>
    </div>

    <template v-if="orderData.orderDtls && orderData.orderDtls.length">
      <div class="cake-info" v-for="(item, index) in orderData.orderDtls" :key="index">
        <van-image class="img" :src="item.mainPic" alt=""></van-image>

        <div class="cake-info-content">
          <div class="row mb-10">
            <span class="name van-ellipsis"
              >{{item.name}}</span
            >
            <span class="num">x {{item.num}}</span>
          </div>

          <div class="row">
            <span class="remark"
              >{{orderData.description}}</span
            >
          </div>
        </div>
      </div>
    </template>

    <div class="summary-info">
      <span class="c-999">下单时间: {{orderData.orderTimeStr}}</span>
      <span class="c-333">共{{orderData.orderDtls ? orderData.orderDtls.length : 0}}件商品
         <!-- 合计: <span class="fz-16 fw-bold">¥ {{orderData.totalPriceYuan}}</span> --></span>
    </div>

    <div class="footer">
      <van-button size="small" round class="mr-10" @click.stop="goInvoice(orderData.xmbzNo)" v-if="orderData.status == 8">开发票</van-button>
      <van-button size="small" round plain class="mr-10" @click.stop="onEdit" v-if="canEdit(orderData)">修改信息</van-button>
      <van-button size="small" round plain type="danger" @click.stop="onView">查看详情</van-button>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive } from 'vue';
import { useRouter } from 'vue-router'
import { getStatusText, getStatusStyle } from '@/utils/order'
import { goInvoice } from '@/utils/url';

export default defineComponent({
  props: {
    orderData: {
      type: Object,
      default: () => {}
    }
  },
  setup(props) {
    const router = useRouter()
    const state = reactive({})
    const onEdit = () => {
      router.push({
        path: '/order/edit',
        query: {id: props.orderData.id, from: 'list'}
      })
    }
    const onView = () => {
      router.push({
        path: '/order/detail',
        query: {id: props.orderData.id}
      })
    }

    /**
     * 1,4,16： 已接单（可修改）
      5,6,12：生产中（可修改）
      7：配送中（可修改）
     */
    const canEdit = (item) => {
      if ([1,4,16,5,6,7,12].includes(item.status)) {
        return true
      } else {
        return false
      }
    }
    return {
      state,
      onEdit,
      onView,
      getStatusText,
      getStatusStyle,
      canEdit,
      goInvoice,
    }
  }
})
</script>

<style lang="less" scoped>
.order-item {
  padding: 10px;
  background: #fff;
  border-radius: 10px;
  margin-bottom: 10px;
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .status {
      font-size: 12px;
    }
  }
  .cake-info {
    display: flex;
    padding: 12px 0;
    margin: 12px 0;
    border-top: 1px solid #f9f8f8;
    border-bottom: 1px solid #f9f8f8;
    .img {
      width: 70px;
      height: 70px;
      margin-right: 8px;
    }
    &-content {
      flex: 1;
      .row {
        display: flex;
        justify-content: space-between;
      }
      .remark {
        font-size: 12px;
        display: inline-block;
        width: 180px;
        color: #999;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .price {
        color: #756e6e;
        font-weight: bold;
        font-size: 14px;
      }
      .name {
        display: inline-block;
        width: 180px;
        font-size: 14px;
      }
      .num {
        color: #756e6e;
        font-size: 14px;
      }
    }
  }
  .summary-info {
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .footer {
    margin-top: 20px;
    text-align: right;
  }
}
</style>
